package com.jay.tools.web.event;

import androidx.annotation.NonNull;

import java.util.HashMap;

/**
 * Created by tan on 2017/9/22 022.
 * 处理web页面中的点击事件
 */

public class EventManager {

    // event的名字，event
    private static final HashMap<String, Event> EVENTS = new HashMap<>();

    private EventManager() {

    }

    private static class Holder {
        private static final EventManager INSTANCE = new EventManager();
    }

    public static EventManager getInstance() {
        return Holder.INSTANCE;
    }

    public EventManager addEvent(@NonNull String name, @NonNull Event event) {
        EVENTS.put(name, event);
        return this;
    }

    public Event getEvent(@NonNull String action) {
        Event event = EVENTS.get(action);
        if (null == event) {
            return new UndefineEvent();
        }
        return event;
    }

}
